home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 1 / Gold Medal Software Volume 1 (Gold Medal) (1994).iso / prog / tpwprog7.arj / GETTEXT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-07-02  |  2.0 KB  |  81 lines

  1. { gettext.pas -- Get text (if present) from clipboard }
  2.  
  3. program GetText;
  4.  
  5. uses WinTypes, WinProcs, WinCrt, Strings;
  6.  
  7. const
  8.  
  9.   winCrtClassName = 'TPWinCrt';
  10.  
  11. var
  12.  
  13.   HWindow: HWnd;   { Handle to WinCrt window }
  14.   P: PChar;        { Pointer to pasted text }
  15.  
  16. {- Return true if clipboard has some text }
  17. function TextInClipboard(HWindow: HWnd): Boolean;
  18. begin
  19.   TextInClipboard := false;
  20.   if OpenClipboard(HWindow) then
  21.   begin
  22.     if (IsClipboardFormatAvailable(cf_Text) or
  23.       IsClipboardFormatAvailable(cf_OEMText)) then
  24.       TextInClipboard := true;
  25.     CloseClipboard
  26.   end
  27. end;
  28.  
  29. {- If true, P is allocated to a copy of clipboard's text }
  30. function GetClipText(HWindow: HWnd; var P: PChar): Boolean;
  31. var
  32.   GHandle: THandle;
  33.   GPtr: PChar;
  34. begin
  35.   GetClipText := false;
  36.   if TextInClipboard(HWindow) and OpenClipboard(HWindow) then
  37.   begin
  38.     GHandle := GetClipboardData(cf_Text);
  39.     if GHandle <> 0 then
  40.     begin
  41.       GPtr := GlobalLock(GHandle);
  42.       if GPtr <> nil then
  43.       begin
  44.         GetMem(P, StrLen(GPtr) + 1);
  45.         if P <> nil then
  46.         begin
  47.           StrCopy(P, GPtr);
  48.           GetClipText := true
  49.         end;
  50.         GlobalUnlock(GHandle)
  51.       end
  52.     end;
  53.     CloseClipboard
  54.   end
  55. end;
  56.  
  57. begin
  58.   InitWinCrt;  { Registers window class for FindWindow }
  59.   HWindow := FindWindow(winCrtClassName, nil);
  60.   if HWindow = 0 then
  61.     Writeln('*** Unable to find WinCrt''s window handle')
  62.   else begin
  63.     if not TextInClipboard(HWindow) then
  64.       Writeln('No text available in clipboard')
  65.     else begin
  66.       if GetClipText(HWindow, P) then
  67.       begin
  68.         Writeln('>', P);
  69.         StrDispose(P)
  70.       end else
  71.         Writeln('*** Unable to get text from clipboard')
  72.     end
  73.   end
  74. end.
  75.  
  76.  
  77. {--------------------------------------------------------------
  78.   Copyright (c) 1991 by Tom Swan. All rights reserved.
  79.   Revision 1.00    Date: 5/25/1991
  80. ---------------------------------------------------------------}
  81.